<?php

namespace app\admin\model;

use app\admin\model\CommonModel;
use think\Model;

class TalkModel extends CommonModel
{
    const TALK_TYPE    = [1 => '付费', 2 => '订阅'];//聊吧类型
    const TALK_FREE    = 0;//免费
    const IS_RECOMMEND = ['否', '是'];//是否推荐首页
    protected $pk = 'id';//主键，可以用get查询

    //是否为专家
    public function isExpert($admin_id)
    {
        $commonModel = new CommonModel();
        $admin_user  = $commonModel->findWhereData('user', ['id' => $admin_id, 'is_expert' => UserModel::EXPERT_YES], 'id');
        if ($admin_user) {
            return true;
        }
        return false;
    }

    public function getCreateTimeAttr($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    public function buyContent()
    {
        return $this->hasMany('BuyContentModel', 'talk_id');
    }

    public function preResult()
    {
        return $this->hasMany('PreResultModel', 'talk_id');
    }


    public function user()
    {
        return $this->belongsTo('UserModel', 'user_id');
    }


}
